package com.ymatou.iapi.dglogin.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dglogin.parameter.DistributorRegisterBean;
import com.ymatou.iapi.dglogin.parameter.RegisterDistributorBean;
import com.ymatou.iapi.dglogin.service.RegisterDistributorCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*分销员注册
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RegisterDistributor{
	private static RegisterDistributorBean registerdistributorBean;
	private static RegisterDistributorCall registerdistributorCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分销员注册");
	}

	@Before
	public void caseUp() {
		registerdistributorBean=new RegisterDistributorBean();
		registerdistributorCall=new RegisterDistributorCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(registerdistributorCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private RegisterDistributorBean initRegBean() {
		RegisterDistributorBean distributorregisterBean2=new RegisterDistributorBean();
		distributorregisterBean2.setAppSource(60);
		distributorregisterBean2.setClientIp(TestDataManager.getRandomIp());
		distributorregisterBean2.setCountryCode("China");
		distributorregisterBean2.setPassword("123456a");
		distributorregisterBean2.setShopId(1);
		distributorregisterBean2.setTerminalSource(1);
		distributorregisterBean2.setWxAppName(DGUserCallService.TestWxsqSeller);
		distributorregisterBean2.setLoginId(TestDataManager.getRandomNumToHex(9));
		return distributorregisterBean2;
	}
	private void verifyDB(RegisterDistributorBean usercreateBean2, Integer uid) {
		Logger.comment("验证DGUserInfo");
		DGUserWapper DGUserWapper=new DGUserWapper();
		DGUserInfo uinfo = DGUserWapper.selectDGUserInfo(uid).get(0);
		Logger.debug("uinfo:"+FormatUtil.beanToGSONString(uinfo));
		Logger.verifyNotNull(uinfo.getLoginPwd(), "验证LoginPwd");
		if (usercreateBean2.getShopId() != null) {
			Logger.verifyEquals(usercreateBean2.getShopId(), uinfo.getShopId(), "验证getShopId");
		}
		Logger.verifyEquals(true, uinfo.getIsSetPwd(), "验证IsSetPwd");
		if (usercreateBean2.getNickName() != null) {
			Logger.verifyEquals(usercreateBean2.getNickName(), uinfo.getNickname(), "验证Nickname");
		}
//		Logger.verifyEquals(usercreateBean2.getUserGender()==null?0:usercreateBean2.getUserGender(), uinfo.getUserGender(), "验证UserGender");
		Logger.verifyEquals(3, uinfo.getUserType(), "验证UserType");
		Logger.verifyEquals(0, uinfo.getUserStatus(), "验证UserStatus");
		Logger.comment("验证DGUserExtInfo");
		DGUserExtInfo exinfo = DGUserWapper.selectDGUserExtInfo(uid).get(0);
		Logger.debug("exinfo:"+FormatUtil.beanToGSONString(exinfo));
		Logger.verifyEquals(usercreateBean2.getAppSource(), exinfo.getAppSource(), "验证AppSource");
		if (usercreateBean2.getClientIp() != null) {
			Logger.verifyEquals(usercreateBean2.getClientIp(), exinfo.getClientIp(), "验证ClientIp");
		}
		Logger.verifyEquals(usercreateBean2.getCountryCode(), exinfo.getCountryCode(), "验证CountryCode");
		Logger.verifyEquals(usercreateBean2.getTerminalSource()==null?0:usercreateBean2.getTerminalSource(), exinfo.getTerminalSource(), "验证TerminalSource");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RegisterDistributor_001() {
		Logger.start(true,"分销员注册成功");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setNickName("nickname");
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("true", registerdistributorCall.getString("success"), "验证success");
			Integer userId=Integer.valueOf(registerdistributorCall.getString("userId"));
			verifyDB(registerdistributorBean, userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_002() {
		Logger.start(true,"不输入shopId失败");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setShopId(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("false", registerdistributorCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_003() {
		Logger.start(true,"不输入appSource失败");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setAppSource(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("false", registerdistributorCall.getString("success"), "验证success");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_004() {
		Logger.start(true,"不输入terminalSource");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setTerminalSource(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("true", registerdistributorCall.getString("success"), "验证success");
			Integer userId=Integer.valueOf(registerdistributorCall.getString("userId"));
			verifyDB(registerdistributorBean, userId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_005() {
		Logger.start(true,"不输入loginId失败");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setLoginId(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("false", registerdistributorCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_006() {
		Logger.start(true,"不输入password失败");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setPassword(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("false", registerdistributorCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_RegisterDistributor_007() {
		Logger.start(true,"不输入wxAppName失败");
		try {
			registerdistributorBean=initRegBean();
			registerdistributorBean.setWxAppName(null);
			registerdistributorCall.setData(registerdistributorBean);
			registerdistributorCall.callService();			
			Logger.verifyEquals("false", registerdistributorCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}